<% title "#{user_title(@user)} - Libraries.io" %>
<% description "Repositories created and contributed to by #{user_title(@user)}" %>
<%= content_for :meta, render_meta(@user) %>
<div class="row">
  <div class="col-sm-6">
    <h1>
      <%= image_tag @user.avatar_url(100), width: 50, height: 50, alt: @user %>
      <%= @user %>
      <%= link_to fa_icon(@user.host_type.downcase), @user.repository_url, class: 'tip', title: "View #{@user.login} on #{@user.host_type}" %>
      <% if logged_in? && current_user.admin? %>
        <%= link_to 'Edit in Admin', admin_edit_owner_path(@user.host_type.downcase, @user.login), class: 'btn btn-danger ', rel: 'nofollow' %>
      <% end %>
    </h1>
    <% unless @user.org? %>
      <% count = @user.open_source_contributions.count %>
      <% if count > 0 %>
        <p>
          <%= fa_icon 'code' %>
          Tracking <%= number_to_human @user.open_source_contributions.sum(:count) %> commits to <%= number_to_human count %> open source packages
        </p>
      <% end %>
    <% end %>
    <% if @user.bio.present? %>
      <p>
        <%= @user.bio %>
      </p>
    <% end %>
  </div>
  <div class="col-sm-6">
    <br>
    <% if @user.blog.present? %>
      <p>
        Homepage: <%= link_to @user.blog, sanitize_url(@user.blog), :rel => 'nofollow' %>
      </p>
    <% end %>
    <% if @user.company.present? %>
      <p>
        Company: <%= @user.company %>
      </p>
    <% end %>
    <% if @user.location.present? %>
      <p>
        Location: <%= link_to @user.location, "http://maps.google.com/?q=#{ERB::Util.url_encode(@user.location)}" %>
      </p>
    <% end %>
  </div>
</div>

<hr>

<div class="row">
  <div class="col-md-8">
    <div class="row">
      <% if @repositories.length > 0 %>
        <div class="col-sm-6 user-column">
          <h4>Repositories</h4>
          <%= render @repositories %>
          <%= link_to "See all #{@user}'s repositories", user_repositories_path(@user.to_param) %>
        </div>
      <% end %>
      <% if @contributions.length > 0 %>
        <div class="col-sm-6 user-column">
          <h4>Repositories Contributed To</h4>
          <%= render @contributions.map(&:repository)  %>
          <%= link_to "See all #{@user}'s contributions", user_contributions_path(@user.to_param) %>
        </div>
      <% end %>
    </div>
    <div class="row">
      <% if @projects.length > 0 %>
        <div class="col-sm-6 user-column">
          <h4>Published Packages</h4>
          <%= render @projects %>
          <%= link_to "See all #{@user}'s packages", user_projects_path(@user.to_param) %>
        </div>
      <% end %>
      <% if @favourite_projects.length > 0 %>
        <div class="col-sm-6 user-column">
          <h4>Most Used Packages</h4>
          <%= render @favourite_projects %>
          <%= link_to "See all #{@user}'s most used packages", user_dependencies_path(@user.to_param) %>
        </div>
      <% end %>
    </div>
  </div>
  <div class="col-md-4">
    <% if @user.org? %>
      <% if @user.top_contributors.any?  %>
        <h4>
          Top Contributors
          <small>
            <%= link_to "See all", user_contributors_path(@user.to_param) %>
          </small>
        </h4>
        <%= render @user.top_contributors %>
      <% end %>
    <% else %>
      <%#= render 'similar' %>
    <% end %>
  </div>
</div>
<div class="row">
  <div class="col-md-12">
    <p>
      <small class='text-muted'>Last synced: <%= @user.last_synced_at || @user.created_at %></small>
    </p>
    <% unless @user.recently_synced? %>
      <% if logged_in? %>
        <p>
          <%= link_to sync_user_path(@user.to_param), class: 'btn btn-primary btn-xs', method: :post do %>
            <%= fa_icon 'refresh' %>
            Resync
          <% end %>
        </p>
      <% else %>
        <p>
          <small class='text-muted'>
            <%= link_to 'Login', login_path(return_to: request.original_url) %> to resync this page
          </small>
        </p>
      <% end %>
    <% end %>
  </div>
</div>
